package edu.hubu.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import net.moon.jpa.model.BaseEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author moonlan
 * @date 2020/10/18 下午5:14
 */

@Entity
@Table(name = "announcement_type")
//逻辑删除注解，删除sql变成了update
@SQLDelete(sql = "update announcement_type set announcement_type_is_deleted = true where announcement_type_id = ?")
//where条件带上了逻辑删除条件
@Where(clause = "announcement_type_is_deleted = false")
@ApiModel("公告类型")
@JsonIgnoreProperties(value={"hibernateLazyInitializer", "handler", "fieldHandler"})
@Proxy(lazy = false)
public class AnnouncementType extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeId")
    @GenericGenerator(name = "snowflakeId", strategy = "edu.hubu.commons.SnowflakeId",
                      parameters = {@org.hibernate.annotations.Parameter(name = "prefix", value = "ANNOUNCEMENT-TYPE")})
    @Column(name = "announcement_type_id")
    @ApiModelProperty(value = "announcements_type的id", position = 1)
    private String announcementTypeId;

    @Column(name = "announcement_type_name")
    @ApiModelProperty(value = "公告类型名称", position = 2)
    private String announcementTyeName;

    @Column(name = "announcement_type_is_forbidden")
    @ApiModelProperty(value = "公告类型是否被禁用", position = 3)
    private boolean announcementTypeIsForbidden = false;

    @Column(name = "announcement_type_is_deleted")
    @ApiModelProperty(value = "公告类型是否被删除", position = 4)
    private boolean announcementTypeIsDeleted = false;

    @OneToMany(mappedBy = "announcementType", fetch = FetchType.LAZY)
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private List<Announcement> announcement = new ArrayList<>();

    public AnnouncementType(String announcementTypeId, String announcementTyeName, boolean announcementTypeIsForbidden, boolean announcementTypeIsDeleted, List<Announcement> announcement) {
        this.announcementTypeId = announcementTypeId;
        this.announcementTyeName = announcementTyeName;
        this.announcementTypeIsForbidden = announcementTypeIsForbidden;
        this.announcementTypeIsDeleted = announcementTypeIsDeleted;
        this.announcement = announcement;
    }

    public AnnouncementType() {
    }

    public static AnnouncementTypeBuilder builder() {
        return new AnnouncementTypeBuilder();
    }

    public String getAnnouncementTypeId() {
        return this.announcementTypeId;
    }

    public String getAnnouncementTyeName() {
        return this.announcementTyeName;
    }

    public boolean isAnnouncementTypeIsForbidden() {
        return this.announcementTypeIsForbidden;
    }

    public boolean isAnnouncementTypeIsDeleted() {
        return this.announcementTypeIsDeleted;
    }

    public List<Announcement> getAnnouncement() {
        return this.announcement;
    }

    public void setAnnouncementTypeId(String announcementTypeId) {
        this.announcementTypeId = announcementTypeId;
    }

    public void setAnnouncementTyeName(String announcementTyeName) {
        this.announcementTyeName = announcementTyeName;
    }

    public void setAnnouncementTypeIsForbidden(boolean announcementTypeIsForbidden) {
        this.announcementTypeIsForbidden = announcementTypeIsForbidden;
    }

    public void setAnnouncementTypeIsDeleted(boolean announcementTypeIsDeleted) {
        this.announcementTypeIsDeleted = announcementTypeIsDeleted;
    }

    public void setAnnouncement(List<Announcement> announcement) {
        this.announcement = announcement;
    }

    public static class AnnouncementTypeBuilder {
        private String announcementTypeId;
        private String announcementTyeName;
        private boolean announcementTypeIsForbidden;
        private boolean announcementTypeIsDeleted;
        private List<Announcement> announcement;

        AnnouncementTypeBuilder() {
        }

        public AnnouncementTypeBuilder announcementTypeId(String announcementTypeId) {
            this.announcementTypeId = announcementTypeId;
            return this;
        }

        public AnnouncementTypeBuilder announcementTyeName(String announcementTyeName) {
            this.announcementTyeName = announcementTyeName;
            return this;
        }

        public AnnouncementTypeBuilder announcementTypeIsForbidden(boolean announcementTypeIsForbidden) {
            this.announcementTypeIsForbidden = announcementTypeIsForbidden;
            return this;
        }

        public AnnouncementTypeBuilder announcementTypeIsDeleted(boolean announcementTypeIsDeleted) {
            this.announcementTypeIsDeleted = announcementTypeIsDeleted;
            return this;
        }

        public AnnouncementTypeBuilder announcement(List<Announcement> announcement) {
            this.announcement = announcement;
            return this;
        }

        public AnnouncementType build() {
            return new AnnouncementType(announcementTypeId, announcementTyeName, announcementTypeIsForbidden, announcementTypeIsDeleted, announcement);
        }

        public String toString() {
            return "AnnouncementType.AnnouncementTypeBuilder(announcementTypeId=" + this.announcementTypeId + ", announcementTyeName=" + this.announcementTyeName + ", announcementTypeIsForbidden=" + this.announcementTypeIsForbidden + ", announcementTypeIsDeleted=" + this.announcementTypeIsDeleted + ", announcement=" + this.announcement + ")";
        }
    }
}
